Skip to content

Commit

Permalink
x11: remove terrible xdg-screensaver hack
Browse files Browse the repository at this point in the history
I'm tired of dealing with this frequent spawning of xdg-screensaver when
debugging and what not. xdg-screensaver was never a serious tool anyway,
it's more like some self-deprecating joke by FDO folks.

This will affect X11 on GNOME and other DEs. I'm singling out GNOME
though, because they are the ones actively sabotaging any sane
technical solutions and community cooperation.

I have been accused of taking it out on innocent GNOME users, while none
of this will reach GNOME developers. Of course that is not the
intention.
  • Loading branch information
wm4 committed Jul 8, 2020
1 parent b93f142 commit c498b28
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 48 deletions.
44 changes: 44 additions & 0 deletions DOCS/man/mpv.rst
Expand Up @@ -1057,6 +1057,50 @@ works like in older mpv releases:
change, and not apply your additional settings, and/or use a different
profile name.

Linux desktop issues
====================

This subsection describes common problems on the Linux desktop. None of these
problems exist on systems like Windows or OSX.

Disabling Screensaver
---------------------

By default, mpv tries to disable the OS screensaver during playback (only if
a VO using the OS GUI API is active). ``--stop-screensaver=no`` disables this.

A common problem is that Linux desktop environments ignore the standard
screensaver APIs on which mpv relies. In particular, mpv uses the Screen Saver
extension (XSS) on X11, and the idle-inhibit on Wayland.

GNOME is one of the worst offenders, and ignores even the now widely supported
idle-inhibit protocol. (This is either due to a combination of malice and
incompetence, but since implementing this protocol would only take a few lines
of code, it is most likely the former. You will also notice how GNOME advocates
react offended whenever their sabotage is pointed out, which indicates either
hypocrisy, or even worse ignorance.)

Such incompatible desktop environments (i.e. which ignore standards) typically
require using a DBus API. This is ridiculous in several ways. The immediate
practical problem is that it would require adding a quite unwieldy dependency
for a DBus library, somehow integrating its mainloop into mpv, and other
generally unacceptable things.

However, since mpv does not officially support GNOME, this is not much of a
problem. If you are one of those miserable users who want to use mpv on GNOME,
report a bug on the GNOME issue tracker:
https://gitlab.gnome.org/groups/GNOME/-/issues

Alternatively, you may be able to write a Lua script that calls the
``xdg-screensaver`` command line program. (By the way, this a command line
program is an utterly horrible kludge that tries to identify your DE, and then
tries to send the correct DBus command via a DBus CLI tool.) If you find the
idea of having to write a script just so your screensaver doesn't kick in
ridiculous, do not use GNOME, or use GNOME video software instead of mpv (good
luck).

Before mpv 0.33.0, the X11 backend ran ``xdg-screensaver reset`` in 10 second
intervals when not paused. This hack was removed in 0.33.0.

.. include:: options.rst

Expand Down
3 changes: 2 additions & 1 deletion DOCS/man/options.rst
Expand Up @@ -3147,7 +3147,8 @@ Window
always re-enabled when the player is paused.

This is not supported on all video outputs or platforms. Sometimes it is
implemented, but does not work (especially with Linux "desktops").
implemented, but does not work (especially with Linux "desktops"). Read the
`Disabling Screensaver`_ section very carefully.

``--wid=<ID>``
This tells mpv to attach to an existing window. If a VO is selected that
Expand Down
39 changes: 0 additions & 39 deletions video/out/x11_common.c
Expand Up @@ -527,30 +527,6 @@ static void vo_x11_get_bounding_monitors(struct vo_x11_state *x11, long b[4])
XFree(screens);
}

static void *screensaver_thread(void *arg)
{
struct vo_x11_state *x11 = arg;

for (;;) {
sem_wait(&x11->screensaver_sem);
// don't queue multiple wakeups
while (!sem_trywait(&x11->screensaver_sem)) {}

if (atomic_load(&x11->screensaver_terminate))
break;

char *args[] = {"xdg-screensaver", "reset", NULL};
int status = mp_subprocess(args, NULL, NULL, mp_devnull, mp_devnull, &(char*){0});
if (status) {
MP_VERBOSE(x11, "Disabling screensaver failed (%d). Make sure the "
"xdg-screensaver script is installed.\n", status);
break;
}
}

return NULL;
}

int vo_x11_init(struct vo *vo)
{
char *dispName;
Expand All @@ -572,13 +548,6 @@ int vo_x11_init(struct vo *vo)
x11->opts = x11->opts_cache->opts;
vo->x11 = x11;

sem_init(&x11->screensaver_sem, 0, 0);
if (pthread_create(&x11->screensaver_thread, NULL, screensaver_thread, x11)) {
sem_destroy(&x11->screensaver_sem);
goto error;
}
x11->screensaver_thread_running = true;

x11_error_output = x11->log;
XSetErrorHandler(x11_errorhandler);

Expand Down Expand Up @@ -808,13 +777,6 @@ void vo_x11_uninit(struct vo *vo)
XCloseDisplay(x11->display);
}

if (x11->screensaver_thread_running) {
atomic_store(&x11->screensaver_terminate, true);
sem_post(&x11->screensaver_sem);
pthread_join(x11->screensaver_thread, NULL);
sem_destroy(&x11->screensaver_sem);
}

if (x11->wakeup_pipe[0] >= 0) {
close(x11->wakeup_pipe[0]);
close(x11->wakeup_pipe[1]);
Expand Down Expand Up @@ -2013,7 +1975,6 @@ static void xscreensaver_heartbeat(struct vo_x11_state *x11)
(time - x11->screensaver_time_last) >= 10)
{
x11->screensaver_time_last = time;
sem_post(&x11->screensaver_sem);
XResetScreenSaver(x11->display);
}
}
Expand Down
9 changes: 1 addition & 8 deletions video/out/x11_common.h
Expand Up @@ -20,14 +20,11 @@

#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include "osdep/atomic.h"
#include "osdep/semaphore.h"

#include "common/common.h"
#include "osdep/atomic.h"

#include "config.h"
#if !HAVE_GPL
Expand Down Expand Up @@ -75,10 +72,6 @@ struct vo_x11_state {
bool screensaver_enabled;
bool dpms_touched;
double screensaver_time_last;
pthread_t screensaver_thread;
bool screensaver_thread_running;
sem_t screensaver_sem;
atomic_bool screensaver_terminate;

XIM xim;
XIC xic;
Expand Down

3 comments on commit c498b28

@mc4man
Copy link

@mc4man mc4man commented on c498b28 Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit has no ill effect on any recent gnome DE whether using gnome-shell or some other shell or whatever...
So nothing broken yet though I'm sure that with your commitment "Things will be broken" will come true sooner than later.

@CounterPillow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KDE uses XSS on X11, and I've confirmed that this change does not impact KDE at all.

@pkunk
Copy link
Contributor

@pkunk pkunk commented on c498b28 Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another workaround for Gnome is $ gnome-session-inhibit mpv

Please sign in to comment.